﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void ImgBtnDelete_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            if (this.TxtStart.Text == "" || this.TxtEnd.Text == "")
            {

                Response.Write("<script language=javascript>alert('对不起！要删除的起始位置或要删除的字符的个数不能为空！');location='javascript:history.go(-1)'</script>");
            }
            else
            {
                if (Convert.ToInt32(this.TxtStart.Text.Trim()) > this.LblOldStr.Text.Length)
                {
                    Page.RegisterStartupScript("", "<script>alert('对不起！要删除的起始位置错误！请重新输入！')</script>");
                }
                else
                {
                    if (Convert.ToInt32(TxtEnd.Text) > Convert.ToInt32(this.LblOldStr.Text.Length) - Convert.ToInt32(TxtStart.Text))
                    {
                        Page.RegisterStartupScript("", "<script>alert('对不起！要删除的字符的个数错误！请重新输入！')</script>");
                    }
                    else
                    {
                        string BeginStr = this.LblOldStr.Text.ToString().Trim();
                        int BeginInt = Convert.ToInt32(TxtStart.Text);
                        int i = Convert.ToInt32(TxtEnd.Text);
                        string StrEnd = BeginStr.Remove(BeginInt, i);
                        this.LblNewStr.Text = StrEnd;
                    }
                }
            }
        }
        catch (Exception ex)
        {
            Page.RegisterStartupScript("", ex.Message);
        }

    }
    protected void BtnCut_Click(object sender, EventArgs e)
    {
        string str = LblCutOldStr.Text.ToString();
        //TrimStart方法和TrimEnd方法的使用，不能移除字符串中间的@和*
        string str2 = str.TrimStart(new char[] { '@', '*' });
        string str3 = str.TrimEnd(new char[] { '@', '*' });
        LblCutStart.Text = str2;
        LblCutEnd.Text = str3;
    }
}
